package partFour.homeWork.code.code01;

/**
 * 添加学生信息的类
 * 增加了对添加学生信息的判断，以学生ID为唯一，如果已经有相同的ID 则需要重新输入
 * 并且返回了添加的信息。
 */

public class AddStu {
    public static void addStu(){
        System.out.println("请输入学生的ID：");
        int id = StuTest.sc.nextInt();
        for (Student student : StuTest.stuTestList){
            if (student.getId() == id){
                System.out.println("ID是鉴别学生唯一主键，不能相同，请重新输入：");
            }
        }
        System.out.println("请输入学生的姓名：");
        String name = StuTest.sc.next();
        System.out.println("请输入学生的年纪");
        int age = StuTest.sc.nextInt();
        Student student = new Student(age,id,name);
        StuTest.stuTestList.add(student);
        for (Student student1 : StuTest.stuTestList){
            if (student1.getAge() == age && student1.getId() == id
                    && student1.getName() == name
            ){
                System.out.println("添加成功！");
                System.out.println(student1);
            }else {
                System.out.println("添加失败！");
            }

        }

    }
}
